package com.szewec.ps.util;

import com.alibaba.fastjson.JSON;
import com.baidu.mapapi.model.LatLng;
import com.szewec.ps.model.MyPoint;

import java.util.ArrayList;
import java.util.List;

/**
 * 坐标对象相互转换
 */
public class CoorModelChangeUtil {

    public static String changeToMyPoint(List<LatLng> latLngList){
        if (ListUtil.isEmpty(latLngList)){
            return null;
        }
        List<MyPoint> myPointList = new ArrayList<>();
        for (LatLng latLng:latLngList){
            MyPoint myPoint = new MyPoint(latLng.latitude,latLng.longitude);
            myPointList.add(myPoint);
        }
        return JSON.toJSONString(myPointList);
    }

    public static List<LatLng> changeToLatLng(String myPointJsonString){
        List<LatLng> latLngList = new ArrayList<>();
        if (StringUtils.isNotEmpty(myPointJsonString)){
            try {
                List<MyPoint> myPointList = JSON.parseArray(myPointJsonString,MyPoint.class);
                for (MyPoint myPoint:myPointList){
                    LatLng latLng = new LatLng(myPoint.getLatitude(),myPoint.getLongitude());
                    latLngList.add(latLng);
                }
            }catch (Exception e){
                LogUtil.e(e);
            }
        }
        return latLngList;
    }
}
